<?php
namespace plugins\file_manage;
use cmf\lib\Plugin;
use think\Db;
/**Demo插件英文名，改成你的插件英文就行了 继承此库
 * @pluginInfo('name'=>'操作日志','symbol'=>'AdminJournal')
 */
class FileManagePlugin extends Plugin
{
    public $info = [
        'name'        => 'FileManage',
        'title'       => '操作日志',
        'description' => '后台操作日志',
        'status'      => 1,
        'author'      => '卓远网络',
        'version'     => '1.0',
    ];

    public $hasAdmin = 1;//插件是否有后台管理界面

    // 插件安装
    public function install()
    {
        return true;//安装成功返回true，失败false
    }

    // 插件卸载
    public function uninstall()
    {
        return true;//卸载成功返回true，失败false
    }

    //应用开始
    public function appBegin()
    {   
        
            $menuName = request()->path();

            $str=explode('/',$menuName);

            if (count($str)==4 && $str[0]=='plugin') {
                //模块名每个单词首字母转大写 去掉下划线
                $quchu = explode('_',$str[1]);
                $str2 = '';
                foreach ($quchu as $key => $value) {
                    $zhuanhuan = ucfirst($value); //首字母转大写
                    $str2 .= $zhuanhuan;
                }

                //控制器每个单词首字母大写 去掉下划线
                $con1 = explode('_',$str[2]);
                $cont_name = '';
                foreach ($con1 as $key => $value) {
                    $aa = ucfirst($value); //首字母转大写
                    $cont_name .= $aa;
                }

                $control = '\\plugins\\'.$str[1].'\\controller\\'.$cont_name."Controller";

                //待进行异常处理
                $duixiang = new $control(); //实例化对象

                if ($duixiang) {
                    //获取基类名
                    $jl_name = get_parent_class($duixiang);
                    $aa = explode('\\',$jl_name);
                    $aa = $aa[count($aa)-1];
                    switch ($aa) {
                        case 'PluginAdminBaseController':
                            $da['type'] = 1; //后端
                            break;
                        case 'PluginRestBaseController':
                            $da['type'] = 3; //接口
                            break;  
                        case 'PluginBaseController':
                            $da['type'] = 2; //前端
                            break;  
                        default:
                            $da['type'] = 1; //后端
                            break;           
                    }
                } else {
                    $da['type'] = 1; //后端
                }

                

                $da['module_sign'] = $str2; //模块标识
                $plugin = Db::name('plugin')->where('name',$str2)->find(); //读取模块中文名
                $da['module_name'] = $plugin['title'];
            } else {
                $da['type'] = 1; //后端
            }

            $da['time'] = time();
            $da['user_name'] = session('name');
            $da['user_id'] = cmf_get_current_admin_id();
            $da['ip'] = request()->ip(0,true); //get_client_ip();
            $da['request'] = $menuName; //请求路径

            Db::name('admin_journal')->insert($da);
    }

}
